﻿//https://leetcode.cn/problems/n-ary-tree-level-order-traversal/

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root)
    {
        vector<vector<int>> ret;
        if (root == nullptr)
            return ret;
        queue<Node*> q;
        q.push(root);

        while (q.size())
        {
            int sz = q.size();
            vector<int> temp;
            for (int i = 0; i < sz; i++)
            {
                //出队列
                Node* node = q.front();
                q.pop();
                temp.push_back(node->val);

                //入队列
                for (auto& n : node->children)
                {
                    if (n != nullptr)
                    {
                        q.push(n);
                    }
                }
            }
            ret.push_back(temp);
        }

        return ret;

    }
};